<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/9
  Time: 12:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<%@ page import="com.limao.servlet.WebFunction" %>
<%@ page import="com.limao.DBDataClass.CrowdUserAuthClass" %>

<%
    CrowdUserAuthClass user = WebFunction.getUserInfo(request, response);
%>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改姓名</title>
    <style>
        body {
            width: 100%;
            height: 100%;
            background: transparent;
        }
    </style>
</head>
<body ontouchstart="">

<div class="iframeBlock of bcf w100 h100">
    <div class="logintittle of tc pr jz">
        修改姓名<span class="pa cursor" id="close-x">&times;</span>
    </div>
    <div class="of jz" style="width: 90%;">
        <input type="text" name="" id="username" placeholder="原用户名：<%=user.username%>" class="db br3"
               disabled="disabled" style="margin-top: 30px;cursor: not-allowed"/>
        <p class="mgl10 cred f14"></p>
        <input type="text" name="" id="usernameNew" placeholder="新用户名" class="db br3"/>
        <p class="mgl10 cred f14"></p>
        <div class="clearfix of" style="margin-top: 46px;">
            <button type="button" id="loginSub" class="cursor tc cf db w100" onclick="Sub();">修&nbsp;改</button>
        </div>
    </div>
</div>


<script>

    $(window).on("load", function () {
        $("#modifyNameBtn", parent.document).click(function () {
            $("#modifyNameIframeDiv", parent.document).slideDown();
            $(".theme-popover-mask", parent.document).fadeIn();

        })
        $("#close-x").click(function () {
            $("#modifyNameIframeDiv", parent.document).slideUp();
            $(".theme-popover-mask", parent.document).fadeOut();

        })
    })
    
    //判断和过滤
    function errorP(usernameNew,p,textVal){
       if(usernameNew == ""){
       		p.text(textVal);
       		return -1;
       }else if(usernameNew.indexOf("测试")!=-1||usernameNew.indexOf("91")!=-1||usernameNew.indexOf("狸猫")!=-1||usernameNew.indexOf("官方")!=-1){
       		p.text("为了防止侵权，用户昵称内不得含有‘测试’，‘七彩云购’，‘官方’等字样。谢谢合作");
       		return -1;
       }else{
       		p.text("");
       }
    }

    function Sub() {
        var usernameNew = $.trim($('#usernameNew').val());

        if(errorP(usernameNew,$('#usernameNew').next('p'),'你还未填写新用户名')==-1){
        	return false;
        }
		
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 114, name: usernameNew}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {
                    showToast("修改成功！");

                    parent.window.location.reload();

                    // 存储需要刷新用户页面
                    localStorage.setItem("needrefreshpersonalall", 'true');

                    setTimeout(function () {
                        $("#loadingfDiv").fadeOut();
                        $("#close-x").trigger('click');
                    }, 500);
                } else {
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }
</script>
</body>
</html>
